<template>
  <!-- div必须有一个跟元素 -->
  <div class="newsinfo-container">
    <h3>{{newsInfo.title}}</h3>
    <p>
      <span>发表时间:{{newsInfo.add_time|timeFormat}}</span>
      <span>点击:{{newsInfo.click}}数</span>
    </p>
    <div class="content" v-html="newsInfo.content"></div>
    <comment-box :parentId='id'></comment-box>
  </div>
</template>
<script>
import { Toast } from "mint-ui";
import comment from '../subcompents/comment'
export default {
  data() {
    return {
      id: this.$route.params.id, //将url传递过来的id值挂载到data上，方便调用
      newsInfo: {}
    };
  },
  methods: {
    getNewsInfo() {
      this.$http.get("api/getnew/" + this.id).then(function(res) {
        if (res.body.status !== 0) {
          return Toast("新闻列表后台数据请求失败");
        }
        this.newsInfo = res.body.message[0]; //[{}] 只有一条
       
      });
    }
  },
  created(){
      this.getNewsInfo()
  },
  components:{
    'comment-box':comment
  }
  
};
</script>   
<style lang="scss" scoped>
.newsinfo-container {
  padding: 10px;
  h3 {
    font-size: 16px;
    color: red;
    text-align: center;
    margin: 10px 0;
  }
  p {
    font-size: 13px;
    color: #226aff;
    display: flex;
    justify-content: space-between;
    padding-bottom: 5px;
    border-bottom: 1px solid #dbdbe0;
  }
}
</style>
